Fix #18337 - Emit coverage counters at call sites of inlined functions#22922
Open
suyashkumar102 wants to merge 15 commits intodlang:masterfrom
Open
Fix #18337 - Emit coverage counters at call sites of inlined functions#22922suyashkumar102 wants to merge 15 commits intodlang:masterfrom
suyashkumar102 wants to merge 15 commits intodlang:masterfrom
Conversation
inlined functions always showed 0000000 in -cov reports even when called. the standalone function body is never executed at runtime (it's inlined at each call site), so its counters stayed zero. fix: tag the CommaExp chains that expandInline produces with isInlineSequence, then emit coverage counters for those chains in visitComma (e2ir.d). fixes https://issues.dlang.org/show_bug.cgi?id=5848 fixes dlang#18337
…ix/cov-inline-final
Contributor
|
Thanks for your pull request and interest in making D better, @suyashkumar102! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#22922" |
nordlow
reviewed
Apr 13, 2026
parameter copies in expandInline were using vfrom.loc, pointing to the declaration line and inflating its count. using Loc.initial instead so inlineCoverage skips them - only actual body statements get counted.
6f7cf03 to
69c1143
Compare
dkorpel
previously requested changes
Apr 14, 2026
use e.isValid() instead of loc checks Co-authored-by: Dennis <dkorpel@users.noreply.github.com>
expression.h also needs to reflect changes to CommaExp in expression.d.
Declaration statements with valid locations (like int y = x * x) should get coverage counters. Parameter copies already have Loc.initial so they're filtered by the isValid() check.
nordlow
reviewed
Apr 16, 2026
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18337
Ran into this while working on #22911. @nordlow brought it up, and since I was already around the inliner code, I took a look.
Tracing through it:
expandInlinereplaces the call with aCommaExpchainof the inlined body, but the standalone function body is what gets the coverage
counters — but it doesn't execute at runtime. The inlined copy inside the caller
had nothing.
Following @dkorpel's suggestion in #22830,
expandInlinenow tags thoseCommaExpchains withisInlineSequence. InvisitComma(e2ir.d), taggedchains get
incUsageElemfor each sub-expression with a source location fromthe inlined body. Parameter copies use
Loc.initialto avoid inflating countson the declaration line. I’m not entirely sure if that’s the cleanest solution, but it works.
Tested on Windows with the patched compiler :
Before and after on
test_cov.d:Before :
After :
Same fix applies with
-inlineflag, both paths go throughexpandInline:Counter fires correctly for nested inlining too —
inner()called 3 times shows 3:Normal non-inlined coverage unchanged —
never_called()still shows0000000: